<!-- 新增系统设置检测项 -->
<div class="layuimini-main">
	<div class="layui-form layuimini-form" style="width:96%;">

		<div class="layui-form-item">
			<label class="layui-form-label required"> 项目代号 </label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="medicalCode" lay-verify="required" />
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label required"> 项目名称 </label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="medicalName" lay-verify="required" />
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label required">项目类型</label>
			<div class="layui-input-block">
				<select name="medicalType" lay-filter="medicalType" ></select>
			</div>
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label required">项目辅助类型</label>
			<div class="layui-input-block">
				<select name="medicalAssistType" lay-filter="medicalAssistType"></select>
			</div>
		</div>
		
		

		<div class="layui-form-item">
			<label class="layui-form-label required"> 单位 </label>
			<div class="layui-input-block">
				<select name="medicalUnits" lay-filter="medicalUnits"></select>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label required"> 参考值 </label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="medicalReferemce" lay-verify="required" />
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label required"> 检验方法 </label>
			<div class="layui-input-block">
				<select name="medicalMethod" lay-filter="medicalMethod"></select>
			</div>
		</div>

		<!-- 区间 -->
		<div class="layui-form-item">
			<label class="layui-form-label required"> 区间 </label>
			<div class="layui-input-inline" style="width:300px;">
				<div class="layui-inline">
					<input type="text" class="layui-input" name="referemceLow" lay-verify="required" placeholder="最低值" style="width:120px;" />
				</div>
				<div class="layui-inline">
					<input type="text" class="layui-input" name="referemceHigh" lay-verify="required" placeholder="最高值" style="width:120px;" />
				</div>
			</div>
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label required">结果解读</label>
			<div class="layui-input-block">
				<textarea name="medicalSuggest" lay-verify="required" placeholder="请输入结果解读" class="layui-textarea"></textarea>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label required">备注</label>
			<div class="layui-input-block">
				<textarea name="remark" lay-verify="required" placeholder="请输入结果解读" class="layui-textarea"></textarea>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="save"> 保存 </button>
			</div>
		</div>

	</div>
</div>


<script src="lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="lib/jq-module/paigusu.min.js" charset="utf-8"></script>
<script>
	layui.use(['form', 'table', 'layer', 'layarea'], function() {
		var form = layui.form,
			layer = layui.layer,
			table = layui.table,
			layarea = layui.layarea,
			$ = layui.$;

		// 初始化表单，要加上，不然刷新部分组件可能会不加载
		form.render();

		// 当前弹出层，防止ID被覆盖
		var parentIndex = layer.index;

		//自定义验证规则
		// form.verify({
		// 	//第一种写法
		// 	medicalCode: function(value, item) { //value控件值，item表单DOM对象
		// 		if (value.length == 0) {
		// 			return '用户名不能为空';
		// 		}
		// 		if (!new RegExp("^[a-zA-Z0-9_-]{6,16}$").test(value)) { //用户名正则，6到16位（字母，数字，下划线，减号）
		// 			return '用户名必须在6~16位';
		// 		}
		// 	},
		// 	//第二种写法
		// 	medicalName: [/^[a-zA-Z0-9_-]{6,16}$/, '密码必须在6~16位']
		// 	//sex:[/^正则表达式$/, '弹出消息']
		// });


		//监听保存按钮事件
		form.on('submit(save)', function(data) {
			//获得表单数据
			var formData = data.field;
			console.log('获得表单数据', formData);

			//处理表单数据
			// var postData = {
			// 	'menuId': formData.menuId,
			// 	'menuName': formData.menuName
			// }

			//通过ajax请求后端接口，并提交数据
			$.ajax({
				url: 'http://localhost:8006/sccMedicalReport',
				type: 'post',
				data: JSON.stringify(formData),
				contentType:'application/json;charset=UTF-8',
				success: function(result) { //后端响应成功回调函数
					console.log(result);
					//刷新页面
					table.reload('systemSettingId');
				},
				error: function(result) {
					console.log(result);
					//刷新页面
					table.reload('systemSettingId');
				}
			});
			//关闭弹出层
			layer.close(parentIndex);
			return false;
		});
	});
</script>
